<%@ page language="java" pageEncoding="UTF-8" contentType="text/html; charset=utf-8" errorPage="/error.jsp" isELIgnored="false" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.opensymphony.com/oscache" prefix="cache" %>
<%@ taglib uri="http://atleap.blandware.com/taglib" prefix="atleap" %>
<html:xhtml />

<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="LOGGING_IN" scope="page" />
<atleap:constants className="com.blandware.atleap.webapp.util.core.WebappConstants" var="GRID_PAGE_SIZE" />
<atleap:globalProperty name="${pageScope.GRID_PAGE_SIZE}" defaultValue="10" type="integer" var="pageSize" />

<atleap:isUserInRole roles="core-user-changeStatus" var="canChangeStatus" />
<atleap:isUserInRole roles="core-user-assignRolesAndGroups" var="canAssignRolesAndGroups" />
<atleap:isUserInRole roles="core-user-update" var="canUpdate" />
<atleap:isUserInRole roles="core-user-view" var="canView" />
<atleap:isUserInRole roles="core-user-delete" var="canDelete" />

<c:set var="infoCells" value="6" />
<c:set var="constantButtonCells" value="0" />
<c:set var="additionalCells" value="0" />
<c:if test="${canChangeStatus}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>
<c:if test="${canAssignRolesAndGroups}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>
<c:if test="${canUpdate}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>
<c:if test="${canView}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>
<c:if test="${canDelete}">
	<c:set var="additionalCells" value="${additionalCells+1}" />
</c:if>

<atleap:content identifier="information" ignore="true" />
<atleap:grid name="userGrid" pageSize="${pageSize}">
	<atleap:messages property="loggedUserCannotDelete" />
	<atleap:messages property="loggedUserCannotDisable" />
	<atleap:messages property="userNotFound" />
    <table border="0" cellpadding="0" cellspacing="0" class="grid" id="userList">
        <thead>
            <tr>
                <th nowrap="nowrap">
                    <atleap:column fieldName="u.name" fieldKey="core.user.form.name">
                        <atleap:sort>
                            <atleap:message key="${fieldKey}" />
                            <atleap:sortAsc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/ascSort.gif" />"  />
                            </atleap:sortAsc>
                            <atleap:sortDesc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/descSort.gif" />"  />
                            </atleap:sortDesc>
                        </atleap:sort>
                        <atleap:stringFilter>
                            <atleap:filterEnabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterEnabled.gif" />"  />
                            </atleap:filterEnabled>
                            <atleap:filterDisabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterDisabled.gif" />"  />
                            </atleap:filterDisabled>
                        </atleap:stringFilter>
                    </atleap:column>
                </th>
                <th nowrap="nowrap">
                    <atleap:column fieldName="u.firstName" fieldKey="core.user.form.firstName">
                        <atleap:sort>
                            <atleap:message key="${fieldKey}" />
                            <atleap:sortAsc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/ascSort.gif" />"  />
                            </atleap:sortAsc>
                            <atleap:sortDesc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/descSort.gif" />"  />
                            </atleap:sortDesc>
                        </atleap:sort>
                        <atleap:stringFilter>
                            <atleap:filterEnabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterEnabled.gif" />"  />
                            </atleap:filterEnabled>
                            <atleap:filterDisabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterDisabled.gif" />"  />
                            </atleap:filterDisabled>
                        </atleap:stringFilter>
                    </atleap:column>
                </th>
                <th nowrap="nowrap">
                    <atleap:column fieldName="u.lastName" fieldKey="core.user.form.lastName">
                        <atleap:sort>
                            <atleap:message key="${fieldKey}" />
                            <atleap:sortAsc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/ascSort.gif" />"  />
                            </atleap:sortAsc>
                            <atleap:sortDesc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/descSort.gif" />"  />
                            </atleap:sortDesc>
                        </atleap:sort>
                        <atleap:stringFilter>
                            <atleap:filterEnabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterEnabled.gif" />"  />
                            </atleap:filterEnabled>
                            <atleap:filterDisabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterDisabled.gif" />"  />
                            </atleap:filterDisabled>
                        </atleap:stringFilter>
                    </atleap:column>
                </th>
                <th nowrap="nowrap">
                    <atleap:column fieldName="u.email" fieldKey="core.user.form.email">
                        <atleap:sort>
                            <atleap:message key="${fieldKey}" />
                            <atleap:sortAsc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/ascSort.gif" />"  />
                            </atleap:sortAsc>
                            <atleap:sortDesc>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/descSort.gif" />"  />
                            </atleap:sortDesc>
                        </atleap:sort>
                        <atleap:stringFilter>
                            <atleap:filterEnabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterEnabled.gif" />"  />
                            </atleap:filterEnabled>
                            <atleap:filterDisabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterDisabled.gif" />"  />
                            </atleap:filterDisabled>
                         </atleap:stringFilter>
                    </atleap:column>
                </th>
                <th nowrap="nowrap">
                    <atleap:column fieldName="fra.role.name" fieldKey="core.user.form.role">
                        <atleap:message key="core.user.form.freeRoles" />
                        <atleap:setFilter beanId="lookupManager" method="listFreeRolesAssignedToUsers" value="name" label="title">
                            <atleap:filterEnabled>
                                <atleap:queryParameter name="freeRolesFilterEnabled" value="true" />
                            </atleap:filterEnabled>
                            <atleap:filterDisabled>
                                <atleap:queryParameter name="freeRolesFilterEnabled" value="false" />
                            </atleap:filterDisabled>
                            <atleap:filterEnabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterEnabled.gif" />"  />
                            </atleap:filterEnabled>
                            <atleap:filterDisabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterDisabled.gif" />"  />
                            </atleap:filterDisabled>
                         </atleap:setFilter>
                    </atleap:column>
                </th>
                <th nowrap="nowrap">
                    <atleap:column fieldName="g.name" fieldKey="core.user.form.group">
                        <atleap:message key="core.user.form.groups" />
                            <atleap:setFilter beanId="lookupManager" method="listGroups" value="name" label="title">
                            <atleap:filterEnabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterEnabled.gif" />"  />
                            </atleap:filterEnabled>
                            <atleap:filterDisabled>
                                <img border="0" src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/grid/filterDisabled.gif" />"  />
                            </atleap:filterDisabled>
                         </atleap:setFilter>
                    </atleap:column>
                </th>
                <c:if test="${constantButtonCells + additionalCells > 0}">
                    <th colspan="${constantButtonCells + additionalCells}">
                        <img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/spacer.gif" />" border="0"  />
                    </th>
                </c:if>
             </tr>
        </thead>
        <tbody>
            <atleap:contextMenu var="menuId">
                <atleap:rowsIterator beanId="userManager" method="listUsers" var="user" oddClass="oddRow" evenClass="evenRow">
                    <atleap:itemSet>
                        <c:set var="loggedUser" value="${pageContext.request.remoteUser == user.name}" />
                        <atleap:rewriteUrl action="core/user/view" var="defaultUrl">
                            <atleap:param name="name" value="${user.name}" />
                        </atleap:rewriteUrl>
                        <c:set var="onTrClickCode" value="" />
                        <c:set var="tdClass" value="defaultCursorCell" />
                        <c:if test="${canView}">
                            <c:set var="onTrClickCode" value="dispatchGridTrClick(event, this, &#039;${defaultUrl}&#039;);" />
                            <c:set var="tdClass" value="pointerCursorCell" />
                        </c:if>
                        <tr class="${rowClass}" oncontextmenu="return showContextMenu(${menuId}, event, ${indexId});" onclick="${onTrClickCode}">
                            <td class="${tdClass}"><c:out value="${user.name}" escapeXml="true" /></td>
                            <td class="${tdClass}"><c:out value="${user.firstName}" escapeXml="true" /></td>
                            <td class="${tdClass}"><c:out value="${user.lastName}" escapeXml="true" /></td>
                            <td class="${tdClass}"><c:out value="${user.email}" escapeXml="true" /></td>
                            <td class="${tdClass}"><c:out value="${user.freeRolesAsString}" escapeXml="true" /></td>
                            <td class="${tdClass}"><c:out value="${user.groupsAsString}" escapeXml="true" /></td>
                            <atleap:item enabled="${!loggedUser}" includeInContextMenu="${canChangeStatus}" includeInPage="${canChangeStatus}">
                                <td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
                                    <atleap:itemEnabled>
                                        <c:choose>
                                            <c:when test="${user.enabled}">
                                                <atleap:message key="core.user.buttons.disable" var="disableMsg" />
                                                <atleap:itemLink action="core/user/changeStatus?status=disabled" title="${disableMsg}" transaction="true">
                                                    <atleap:param name="name" value="${user.name}" />
													<img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/active.gif" />" border="0" title="${disableMsg}" alt="${disableMsg}" align="absmiddle" />
													<atleap:itemLabel>
														${disableMsg}
													</atleap:itemLabel>
                                                </atleap:itemLink>
                                            </c:when>
                                            <c:otherwise>
                                                <atleap:message key="core.user.buttons.enable" var="enableMsg" />
                                                <atleap:itemLink action="core/user/changeStatus?status=enabled" title="${enableMsg}" transaction="true">
                                                    <atleap:param name="name" value="${user.name}" />
													<img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/inactive.gif" />" border="0" title="${enableMsg}" alt="${enableMsg}" align="absmiddle" />
													<atleap:itemLabel>
														${enableMsg}
													</atleap:itemLabel>
                                                </atleap:itemLink>
                                            </c:otherwise>
                                        </c:choose>
                                    </atleap:itemEnabled>
                                    <atleap:itemDisabled>
                                        <atleap:message key="core.user.form.changeStatusDisabled" var="changeStatusDisabledMsg" />
                                        <atleap:itemLink title="${changeStatusDisabledMsg}">
											<img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/active.gif" />" border="0" alt="${changeStatusDisabledMsg}" title="${changeStatusDisabledMsg}"  align="absmiddle" />
											<atleap:itemLabel>
												${changeStatusDisabledMsg}
											</atleap:itemLabel>
                                        </atleap:itemLink>
                                    </atleap:itemDisabled>
                                </td>
                            </atleap:item>
                            <atleap:item includeInContextMenu="${canAssignRolesAndGroups}" includeInPage="${canAssignRolesAndGroups}">
                                <td align="center" width="20" height="20" valign="middle" class="defaultCursorCell">
                                    <atleap:itemEnabled>
                                        <atleap:message key="core.commons.buttons.assignRolesAndGroups" var="assignRolesAndGroupsMsg"/>
                                        <atleap:itemLink action="core/user/callAssignRolesAndGroups" title="${assignRolesAndGroupsMsg}">
                                            <atleap:param name="userName" value="${user.name}" />
												<img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/assign_roles.gif" />" border="0" title="${assignRolesAndGroupsMsg}" alt="${assignRolesAndGroupsMsg}" align="absmiddle" />
												<atleap:itemLabel>
													${assignRolesAndGroupsMsg}
												</atleap:itemLabel>
                                        </atleap:itemLink>
                                    </atleap:itemEnabled>
                                </td>
                            </atleap:item>
                            <atleap:item includeInContextMenu="${canUpdate}" includeInPage="${canUpdate}">
                                <td width="20" height="20" align="center" valign="middle" class="defaultCursorCell">
                                    <atleap:itemEnabled>
                                        <atleap:message key="core.commons.buttons.callUpdate" var="callUpdateMsg" />
                                        <atleap:itemLink action="core/user/callUpdate" title="${callUpdateMsg}">
                                            <atleap:param name="name" value="${user.name}" />
                                            <atleap:param name="${pageScope.LOGGING_IN}" value="true" />
												<img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/edit.gif" />" border="0" title="${callUpdateMsg}" alt="${callUpdateMsg}" align="absmiddle" />
												<atleap:itemLabel>
													${callUpdateMsg}
												</atleap:itemLabel>
                                        </atleap:itemLink>
                                    </atleap:itemEnabled>
                                </td>
                            </atleap:item>
                            <atleap:item includeInContextMenu="${canView}" includeInPage="${canView}">
                                <td colspan="${colspan}" width="20" height="20" align="center" valign="middle" class="defaultCursorCell">
                                    <atleap:itemEnabled>
                                        <atleap:message key="core.commons.buttons.view" var="viewMsg"/>
                                        <atleap:itemLink action="core/user/view" title="${viewMsg}">
                                            <atleap:param name="name" value="${user.name}" />
												<img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/view.gif" />" border="0" title="${viewMsg}" alt="${viewMsg}" align="absmiddle" />
												<atleap:itemLabel>
													${viewMsg}
												</atleap:itemLabel>
                                        </atleap:itemLink>
                                    </atleap:itemEnabled>
                                </td>
                            </atleap:item>
                            <atleap:item enabled="${!loggedUser}" includeInContextMenu="${canDelete}" includeInPage="${canDelete}">
                                <atleap:message key="core.commons.buttons.delete" var="deleteTitle" />
                                <td width="20" height="20" align="center" valign="middle" class="defaultCursorCell">
                                    <atleap:itemEnabled>
                                        <atleap:itemLink action="core/user/delete" transaction="true" confirmExpression="confirmDelete();" title="${deleteTitle}">
                                            <atleap:param name="name" value="${user.name}" />
												<img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/delete.gif" />" border="0" title="${deleteTitle}" alt="${deleteTitle}" align="absmiddle" />
												<atleap:itemLabel>
													${deleteTitle}
												</atleap:itemLabel>
                                        </atleap:itemLink>
                                    </atleap:itemEnabled>
                                    <atleap:itemDisabled>
                                        <atleap:message key="core.user.form.loggedUser.cannotDelete" var="cannotDeleteMsg" />
                                        <atleap:itemLink title="${cannotDeleteMsg}">
											<img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/deleteDisabled.gif" />" border="0" alt="${cannotDeleteMsg}" title="${cannotDeleteMsg}" align="absmiddle" />
											<atleap:itemLabel>
												${deleteTitle}
											</atleap:itemLabel>
                                        </atleap:itemLink>
                                    </atleap:itemDisabled>
                                </td>
                            </atleap:item>
                        </tr>
                    </atleap:itemSet>
                </atleap:rowsIterator>
            </atleap:contextMenu>
            <atleap:noRows>
                <tr>
                    <td class="tfoot" colspan="${infoCells + constantButtonCells + additionalCells}" align="center">
                       <em><atleap:message key="core.commons.nothingToShow"/></em>
                    </td>
                </tr>
            </atleap:noRows>
        </tbody>
        <tfoot>
            <tr>
                <atleap:pager pageCount="10">
                    <td colspan="${infoCells + constantButtonCells + additionalCells}" align="center">
                        <atleap:message key="core.grid.pager.title" />&nbsp;
                        <atleap:firstPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/first.gif" />" border="0" alt="<atleap:message key="core.grid.pager.first"/>" title="<atleap:message key="core.grid.pager.first"/>" /></atleap:firstPage>
                        <atleap:prevPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/prev.gif" />" border="0" alt="<atleap:message key="core.grid.pager.prev"/>" title="<atleap:message key="core.grid.pager.prev"/>" /></atleap:prevPage>
                        <atleap:pagesIterator>
                            <atleap:page>${pageNumber}&nbsp;</atleap:page>
                            <atleap:currentPage><b>${pageNumber}</b>&nbsp;</atleap:currentPage>
                        </atleap:pagesIterator>
                        <atleap:nextPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/next.gif" />" border="0" alt="<atleap:message key="core.grid.pager.next"/>" title="<atleap:message key="core.grid.pager.next"/>" /></atleap:nextPage>
                        <atleap:lastPage><img src="<atleap:rewriteUrl href="/images/theme/${appConfig['adminCssTheme']}/last.gif" />" border="0" alt="<atleap:message key="core.grid.pager.last"/>" title="<atleap:message key="core.grid.pager.last"/>" /></atleap:lastPage>
                    </td>
                </atleap:pager>
            </tr>
        </tfoot>
    </table>
    <atleap:isUserInRole roles="core-user-create">
        <atleap:form action="core/user/callCreate" method="POST" validateOnSubmit="false">
            <atleap:submit styleClass="button"><atleap:message key="core.commons.buttons.create" /></atleap:submit>
        </atleap:form>
    </atleap:isUserInRole>
</atleap:grid>


